import 'package:flutter/material.dart';

class GestureHandler extends StatelessWidget {
  final Widget child;
  final VoidCallback? onSwipeUp;
  final VoidCallback? onSwipeDown;
  final VoidCallback? onDoubleTap;
  final VoidCallback? onLongPress;

  const GestureHandler({
    super.key,
    required this.child,
    this.onSwipeUp,
    this.onSwipeDown,
    this.onDoubleTap,
    this.onLongPress,
  });

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onVerticalDragEnd: (details) {
        if (details.primaryVelocity! < -1000) {
          // 向上滑动
          onSwipeUp?.call();
        } else if (details.primaryVelocity! > 1000) {
          // 向下滑动
          onSwipeDown?.call();
        }
      },
      onDoubleTap: onDoubleTap,
      onLongPress: onLongPress,
      child: child,
    );
  }
}
